/*
 * Created on 29/06/2006
 *
 */
package ar.com.cubika.trainees.view;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ar.com.cubika.trainees.bean.transportes.Chofer;
import ar.com.cubika.trainees.bean.transportes.Empresa;

public class EliminarChoferServlet extends HttpServlet {
    
    

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	
    	String dni = request.getParameter("chofer");
    	int i = 0;
    	int posChoferEnArray = 0;
    	boolean borrar = false;
    	int principioDNI;
    	principioDNI = dni.indexOf(':')+1;
    	
    	dni = dni.substring(principioDNI, dni.length());
    	
    	for(Chofer c:Empresa.getChoferes()){
    		
    		if(c.getDni().equals(dni)){
    			posChoferEnArray = i;
    			borrar = true;
    		}
    		i++;
    	}
    	
    	if(borrar)
    	Empresa.getChoferes().remove(posChoferEnArray);
    	
    	
        request.getRequestDispatcher("/viewEmpresa").forward(
                request, response);
        
    }
    
    

}